package com.habdqn.studentmanager.converter;

import java.math.BigDecimal;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;

public class BigDecimalConverter implements Converter<String, BigDecimal> {

	private static Logger logger = LoggerFactory.getLogger(BigDecimalConverter.class);
	
	@Override
	public BigDecimal convert(String source) {
		BigDecimal value = null;
		
		// 先判断
		if (StringUtils.isEmpty(source)) {
			return value;
		}
		
		try {
			value = new BigDecimal(source);
		}
		catch (NumberFormatException e) {
			logger.error("{} 转换 BigDecimal 出错.", source, e);
		}
		
		return value;
	}

}
